﻿using DataService.Office.Word;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Data;
using DataService.Office.WordDTO;
using DataService.Office.ExcelDTO;

namespace DataService.Office.WordMain
{
    public interface IXmlPackageBussiness
    {

        /// <summary>
        /// 段落 后 创建表格元素
        /// </summary>
        /// <param name="docBody"></param>
        /// <param name="element">当前元素</param>
        /// <returns>表格元素</returns>
        Table TableAfterXmlElement(Body docBody, OpenXmlElement element);


        /// <summary>
        /// 段落 前 创建表格元素
        /// </summary>
        /// <param name="docBody"></param>
        /// <param name="element">当前元素</param>
        /// <returns>表格元素</returns>
        Table TableBeforeXmlElement(Body docBody, OpenXmlElement element);

        /// <summary>
        /// 新创建一个段落
        /// </summary>
        Paragraph ParagraphAfterXmlElement(Body docBody, OpenXmlElement xmlElement);

        /// <summary>
        /// 表格中插入文本
        /// </summary>
        /// <param name="cellMerge">横向合并参数</param>
        /// <param name="verticaMergeList">纵向合并参数</param>
        void AddTextTable(Table weekTable, DataTable dataTable, List<TableMergeCellDTO> cellMerge, List<TableVerticalMergeDTO> verticaMergeList, List<TableTextStyle> tableTextStyles);
        /// <summary>
        /// 插入模板表格
        /// </summary>
        /// <param name="mainPart"></param>
        /// <param name="tagertTable"></param>
        /// <param name="wordTableDTOArray"></param>
        /// <param name="wordAppendDataDTO"></param>
        void AddTemplateDataTable(MainDocumentPart mainPart, Table tagertTable, List<WordTableDTO> wordTableDTOArray, WordAppendRowDTO wordAppendDataDTO);
        /// <summary>
        /// 表格写入图片和文本，
        /// 如果只是在表格中插入文本，建议使用 AddTextTable
        /// </summary>
        /// <param name="lstData">数据行</param>
        /// <param name="headerArray">表头，不能去重</param>
        void AddImgTextTable(Table table, List<object[]> lstData, string[] headerArray);
        /// <summary>
        /// 段落追加标题
        /// </summary>
        /// <param name="paragraph">需要添加标题的段落</param>
        /// <param name="text">标题</param>
        /// <param name="level">几级标题，1-9</param>
        void ParagraphAppendTitle(Paragraph paragraph, string text, int level);

        /// <summary>
        ///段落添加图片
        /// </summary>
        /// <param name="mainPart">主文档 </param>
        /// <param name="paragraph">当前段落</param>
        /// <param name="imgPathList">图片全路径</param>
        OpenXmlElement AddImageToParagraph(MainDocumentPart mainPart, Paragraph paragraph, List<string> imgPathList);


        /// <summary>
        /// 段落添加图片
        /// </summary>
        /// <param name="mainPart">主文档</param>
        /// <param name="paragraph">当前段落</param>
        /// <param name="imgPathList">图片全路径</param>
        /// <param name="imgWidth">图片宽度 单位：cm</param>
        /// <param name="imgHeight">图片高度 单位：cm</param>
        OpenXmlElement AddImageToParagraph(MainDocumentPart mainPart, Paragraph paragraph, List<string> imgPathList, decimal imgWidth, decimal imgHeight);



        /// <summary>
        /// 段落添加多张图片；设置图片宽度可以 并排横向展示多张图片
        /// </summary>
        /// <param name="mainPart">主文档</param>
        /// <param name="paragraph">当前段落</param>
        /// <param name="imgPathList">图片全路径</param>
        /// <param name="imgWidth">图片宽度 单位：cm</param>
        /// <param name="imgHeight">图片高度 单位：cm</param>
        OpenXmlElement MulitipImgsToParagraph(MainDocumentPart mainPart, Paragraph paragraph, List<string> imgPathList, decimal imgWidth, decimal imgHeight);

        /// <summary>
        /// 段落添加图片
        /// </summary>
        /// <param name="mainPart">主文档</param>
        /// <param name="paragraph">当前段落</param>
        /// <param name="drawingDTOs">图片集合参数</param>
        OpenXmlElement AddImageToParagraph(MainDocumentPart mainPart, Paragraph paragraph, List<DrawingDTO> drawingDTOs);
        /// <summary>
        /// 段落添加多张图片；设置图片宽度可以 并排横向展示多张图片
        /// </summary>
        /// <param name="mainPart">主文档</param>
        /// <param name="paragraph">当前段落</param>
        /// <param name="drawingDTOs">附件参数</param>
        OpenXmlElement MulitipImgsToParagraph(MainDocumentPart mainPart, Paragraph paragraph, List<DrawingDTO> drawingDTOs);
        /// <summary>
        /// 当前段落【追加】文本
        /// </summary>
        /// <param name="paragraph">当前段落</param>
        /// <param name="text"></param>
        void ParagraphAppendText(Paragraph paragraph, string text);

        /// <summary>
        /// 返回选择标题下第一个子标题元素；若没有找到标题则返回最后一个元素
        /// </summary>
        /// <param name="mainPart"></param>
        /// <param name="title"></param>
        /// <returns>标题下第一个子标题元素</returns>
        XmlElementDTO GetSonFirstElementOfTitle(MainDocumentPart mainPart, string title);

        /// <summary>
        /// 返回 标题下最后一个子标题元素；若没有找到标题则返回最后一个元素
        /// </summary>
        /// <param name="mainPart"></param>
        /// <param name="title"></param>
        /// <param name="titlelvl"></param>
        /// <returns>标题下最后一个子标题元素</returns>
        XmlElementDTO GetLastElementOfTitle(MainDocumentPart mainPart, string title, int titlelvl);
        /// <summary>
        /// 获取一级标题
        /// </summary>
        /// <param name="mainPart"></param>
        /// <returns>一级标题</returns>
        List<XmlTtitleDTO> GetXmlFirstTitles(MainDocumentPart mainPart);
        /// <summary>
        /// 保存文档
        /// </summary>
        /// <param name="newLevelList">需要添加的标题集合</param>
        void Save(MainDocumentPart mainPart, List<int> newLevelList);

        void Dispose(WordprocessingDocument wd);

        /// <summary>
        /// 创建docx文件
        /// </summary>
        /// <param name="newFileName">文件全路径</param>
        /// <returns></returns>
        WordprocessingDocument CreateDocumentPart(string newFileName);
        /// <summary>
        /// 获取word部件相对路径
        /// </summary>
        /// <param name="sourceMainDocumentPart">源顶级包</param>
        /// <returns></returns>
        List<Uri> GetPartWordFileUris(MainDocumentPart sourceMainDocumentPart);
        /// <summary>
        /// 打开指定包路径部件
        /// </summary>
        /// <param name="sourceWD">源顶级包</param>
        /// <param name="uri"> word/xx.docx   word/media/xxx.jpg 等 </param>
        /// <returns></returns>
        WordprocessingDocument OpenUriDocument(WordprocessingDocument sourceWD, Uri uri);
        /// <summary>
        /// 打开现有文档
        /// </summary>
        /// <returns></returns>
        WordprocessingDocument OpenDocumentPart(string filePath);
        /// <summary>
        /// 创建分节符
        /// </summary>
        /// <param name="body"></param>
        void AddPageBreak(OpenXmlElement xmlElement);
        /// <summary>
        /// 新起一页；创建分节符
        /// </summary>
        /// <param name="xmlElement"></param>
        void AddNewPageBreak(OpenXmlElement xmlElement);
        /// <summary>
        /// 纸张设置为纵向
        /// </summary>
        void SetPageOrientation(OpenXmlElement xmlElement);
        /// <summary>
        /// 设置为横向
        /// </summary>
        /// <param name="xmlElement"></param>
        void SetPageLandscape(OpenXmlElement xmlElement);
        bool MergeWordFiles(MainDocumentPart mainPart, List<string> sourcePaths, OpenXmlElement targetElement);
        Body CreateBody(MainDocumentPart mainPart);
        /// <summary>
        /// 设置word样式
        /// 设置内容包含：标题和正文、插图、表格
        /// </summary>
        /// <param name="mainPart"></param>
        /// <param name="titleStyleDic">标题样式, key:标题大纲级别，Value:样式 , 标题取值范围1-9；key=0:正文</param>
        /// <param name="tableHeaderStyleDTO">表格 表头样式</param>
        /// <param name="tableRowStyleDTO">表格 内容样式</param>
        /// <param name="contentStyleDTO">正文排版</param>
        /// <returns></returns>
        bool SetWordStyle(MainDocumentPart mainPart, Body body, Dictionary<int, XmlTextStyleDTO> titleStyleDic, XmlTextStyleDTO contentStyleDTO, XmlTextStyleDTO tableHeaderStyleDTO, XmlTextStyleDTO tableRowStyleDTO, XmlTextStyleDTO picStyleDTO, Action<string> action, CancellationTokenSource cts, AutoResetEvent are);

        /// <summary>
        /// 设置表格样式
        /// </summary>
        /// <param name="tableHeaderStyleDTO">表头样式</param>
        /// <param name="tableRowStyleDTO">内容行样式</param>
        /// <returns></returns>
        bool SetWordTableStyle(MainDocumentPart mainPart, Body body, XmlTextStyleDTO tableHeaderStyleDTO, XmlTextStyleDTO tableRowStyleDTO, Action<string> action, CancellationTokenSource cts, AutoResetEvent are);
        /// <summary>
        /// 设置标题和正文样式
        /// </summary>
        /// <param name="titleStyleDic">标题样式</param>
        /// <param name="contentStyleDTO">正文样式</param>
        /// <returns></returns>
        bool SetWordTileAndTextStyle(MainDocumentPart mainPart, Body body, Dictionary<int, XmlTextStyleDTO> titleStyleDic, XmlTextStyleDTO contentStyleDTO, Action<string> action, CancellationTokenSource cts, AutoResetEvent are);
        /// <summary>
        /// 设置插图样式
        /// </summary>
        bool SetWordPicStyle(MainDocumentPart mainPart, Body body, XmlTextStyleDTO picStyleDTO, Action<string> action, CancellationTokenSource cts, AutoResetEvent are);

        /// <summary>
        /// 将excel内容转到word
        /// </summary>
        /// <param name="wordFullPath">word全路径</param>
        /// <param name="excelFullPath">excel全路径</param>
        /// <param name="paramSheets">sheet列表</param>
        /// <param name="header">页眉</param>
        /// <param name="footer">页脚</param>
        /// <returns></returns>
        bool WordInExcel(string wordFullPath, string excelFullPath, List<ExcelToWordParmDTO> excelToWordParmDTOs, string header, string footer);


        HeadFootDTO GetHeadFootText(string wordFullPath);

        void AddHeader(MainDocumentPart mainDocPart, string paramHeader);
        void AddFooter(MainDocumentPart mainDocPart, string paramHeader);
        void AppendHeader(MainDocumentPart mainDocPart, string paramHeader);
        /// <summary>
        /// Word添加水印
        /// </summary>
        bool AddWaterMark(MainDocumentPart mainPart, string waterText);
        bool ValidateWord(string filePath);




    }
}
